<?php
/********************************************************
 *
 * 此文件的作用:
 *		用户表的入口
 *
 * @copyright Copyright (c) 2008-2009
 * @author 刘昌功 lcg635@126.com
 *
 ********************************************************/
defined('APP_DIR') or die("404 Not Found");

FLEA::loadClass('FLEA_Com_RBAC_UsersManager');

class Table_User extends FLEA_Com_RBAC_UsersManager {
    var $tableName = 'user';
    var $primaryKey = 'user_id';
	var $encodeMethod = PWD_MD5;

	var $functionFields = array(
		'registerIpField' => null,
		'lastLoginField' => null,
		'lastLoginIpField' => 'lastLoginIp',
		'loginCountField' => null,
		'isLockedField' => null
	);

	var $hasOne = array(
		//与员工表关联
		array(
			'tableClass' => 'Table_Worker',
			'foreignKey'=>'user_id',
			'mappingName'=>'work',
			'enabled' => false
		),
		//与教员表关联
		array(
			'tableClass' => 'Table_Teacher',
			'foreignKey'=>'user_id',
			'mappingName'=>'teacher',
			'enabled' => false
		)
	);

	var $_ui = null;

	function form($type = 'login', $data = null) {
		$this->_ui = FLEA::initWebControls();
		switch ($type) {
			case 'login' : return $this->loginForm($data); break;
			case 'register' : return $this->registerForm($data); break;
			case 'modify' : return $this->modifyForm($data); break;
		}
	}

	function loginForm($data) {
		$form = array(
			'username' => $this->_ui->control('Textbox', 'username',
				array(
					'value' => $data['username'],
					'maxlength' => 18
				),
				true
			),
			'password' => $this->_ui->control('Password', 'password',
   				array(
       		 		'maxlength' => 18
    			),
				true
			)
		);
		return $form;
	}

	function registerForm($data) {
		$form = array(
			'username' => $this->_ui->control('Textbox', 'username',
				array(
					'maxlength' => 18
				),
				true
			),
			'password' => $this->_ui->control('Password', 'password',
   				array(
					'id' => 'pwd',
       		 		'maxlength' => 18
    			),
				true
			),
			'confirmPassword' => $this->_ui->control('Password', 'confirmPassword',
   				array(		
					'id' => 'confirmPwd',
       		 		'maxlength' => 18
    			),
				true
			),
			'trueName' => $this->_ui->control('Textbox', 'trueName',
				array(
				),
				true
			),
			'politics' => $this->_ui->control('RadioGroup', 'politics',
				array(
					'items' => array('共产党员' => 0, '共青团员' => 1, '其它'=>2),
					'selected' => 1
				),
				true
			),
			'num' => $this->_ui->control('Textbox', 'num',
				array(				
				),
				true
			),
			'sex' => $this->_ui->control('RadioGroup', 'sex',
				array(
					'items' => array('男' => 0, '女' => 1),
					'selected' => 0
				),
				true
			),
			'province' => $this->_ui->control('DropdownList', 'province',
				array(
					'selected' => '广东',
					'items' => array('请选择' => '',
									  '北京' => '北京',
						              '上海' => '上海',
						              '天津' => '天津',
						              '重庆' => '重庆',
						              '河北' => '河北',
						              '山西' => '山西',
						              '辽宁' => '辽宁',
						              '吉林' => '吉林',
						              '黑龙江' => '黑龙江',
						              '江苏' => '江苏',
						              '浙江' => '浙江',
						              '安徽' => '安徽',
						              '福建' => '福建',
						              '江西' => '江西',
						              '山东' => '山东',
						              '河南' => '河南',
						              '湖北' => '湖北',
						              '湖南' => '湖南',
						              '广东' => '广东',
						              '海南' => '海南',
						              '四川' => '四川',
						              '贵州' => '贵州',
						              '云南' => '云南',
						              '陕西' => '陕西',
						              '甘肃' => '甘肃',
						              '青海' => '青海',
						              '内蒙古' => '内蒙古',
						              '广西' => '广西区',
						              '西藏' => '西藏',
						              '宁夏' => '宁夏',
						              '新疆' => '新疆',
						              '台湾' => '台湾',
						              '香港' => '香港',
						              '澳门' => '澳门',
						              '国外' => '国外',
									)
				),
				true
			),
			'poor' => $this->_ui->control('RadioGroup', 'poor',
				array(
					'items' => array('有绿卡' => 1, '无绿卡但有贫困证明'=>2, '均无' => 0),
					'selected' => 0
				),
				true
			),
			'userType' => $this->_ui->control('RadioGroup', 'userType',
				array(
					'items' => array('本科内招'=>0, '自筹研究生'=>1),
					'selected' => 0
				),
				true
			),
			'college' => $this->_ui->control('DropdownList', 'college',
				array(
					'onChange' => 'selectDepartment()',
					
					'items' => array('请选择：'=>'')
				),
				true
			),			
			'department' => $this->_ui->control('DropdownList', 'department',
				array(
					'onChange' => 'selectMajor()',
					'items' => array('请选择：'=>'')
				),
				true
			),
			'major' => $this->_ui->control('DropdownList', 'major',
				array(
					'items' => array('请选择：'=>'')
				),
				true
			),
			'room' => $this->_ui->control('Textbox', 'room',
				array(
				),
				true
			),
			'bankCardNum' => $this->_ui->control('Textbox', 'bankCardNum',
				array(
				),
				true
			),
			'tel' => $this->_ui->control('Textbox', 'tel',
				array(
				),
				true
			),
			'email' => $this->_ui->control('Textbox', 'email',
				array(	
				),
				true
			),
			'pic' => $this->_ui->control('FileUpload', 'pic',
				array(
				),
				true
			),
			'question' => $this->_ui->control('Textbox', 'question',
				array(
				),
				true
			),
			'answer' => $this->_ui->control('Textbox', 'answer',
				array(
				),
				true
			)
		);
		return $form;
	}

		function modifyForm($data) {
		$form = array(
			'user_id' => $this->_ui->control('Hidden', 'user_id',
				array(
					'value' => $data['user_id']
				),
				true
			),
			'province' => $this->_ui->control('DropdownList', 'province',
				array(
					'items' => array('请选择' => '',
								   	'北京' => '北京',
						              '上海' => '上海',
						              '天津' => '天津',
						              '重庆' => '重庆',
						              '河北' => '河北',
						              '山西' => '山西',
						              '辽宁' => '辽宁',
						              '吉林' => '吉林',
						              '黑龙江' => '黑龙江',
						              '江苏' => '江苏',
						              '浙江' => '浙江',
						              '安徽' => '安徽',
						              '福建' => '福建',
						              '江西' => '江西',
						              '山东' => '山东',
						              '河南' => '河南',
						              '湖北' => '湖北',
						              '湖南' => '湖南',
						              '广东' => '广东',
						              '海南' => '海南',
						              '四川' => '四川',
						              '贵州' => '贵州',
						              '云南' => '云南',
						              '陕西' => '陕西',
						              '甘肃' => '甘肃',
						              '青海' => '青海',
						              '内蒙古' => '内蒙古',
						              '广西' => '广西区',
						              '西藏' => '西藏',
						              '宁夏' => '宁夏',
						              '新疆' => '新疆',
						              '台湾' => '台湾',
						              '香港' => '香港',
						              '澳门' => '澳门',
						              '国外' => '国外',
									),
					'selected' => $data['province']
				),
				true
			),
			'sex' => $this->_ui->control('RadioGroup', 'sex',
				array(
					'items' => array('男' => 0, '女' => 1),
					'selected' => $data['sex']
				),
				true
			),
			'politics' => $this->_ui->control('RadioGroup', 'politics',
				array(
					'items' => array('共产党员' => 0, '共青团员' => 1, '其它'=>2),
					'selected' => $data['politics']
				),
				true
			),
			'email' => $this->_ui->control('Textbox', 'email',
				array(
					'value' => $data['email']
				),
				true
			),
			'poor' => $this->_ui->control('RadioGroup', 'poor',
				array(
					'items' => array('有绿卡' => 1, '无绿卡但有贫困证明'=>2, '均无' => 0),
					'selected' => $data['poor']
				),
				true
			),
			'college' => $this->_ui->control('DropdownList', 'college',
				array(
					'onChange' => 'selectDepartment()',
					'items' => array($data['college']=>$data['college'])
				),
				true
			),
			'department' => $this->_ui->control('DropdownList', 'department',
				array(
					'selected' => $data['department'],
					'onChange' => 'selectMajor()',
					'items' => array($data['department']=>$data['department'])
				),
				true
			),			
			'major' => $this->_ui->control('DropdownList', 'major',
				array(
					'selected' => $data['major'],
					'items' => array($data['major']=>$data['major'])
				),
				true
			),
			'room' => $this->_ui->control('Textbox', 'room',
				array(
					'value' => $data['room']
				),
				true
			),
			'trueName' => $this->_ui->control('Textbox', 'trueName',
				array(
					'value' => $data['trueName']
				),
				true
			),
			'tel' => $this->_ui->control('Textbox', 'tel',
				array(
					'value' => $data['tel']
				),
				true
			),
			'bankCardNum' => $this->_ui->control('Textbox', 'bankCardNum',
				array(
					'value' => $data['bankCardNum']
				),
				true
			),
			'userType' => $this->_ui->control('RadioGroup', 'userType',
				array(
					'items' => array('本科内招'=>0, '自筹研究生'=>1),
					'selected' => $data['userType']
				),
				true
			),
			'pic' => $this->_ui->control('FileUpload', 'pic',
				array(
					'onChange' => 'view()'
				),
				true
			)
		);
		return $form;
	}
}
